package com.king.jconsole;

import java.util.ArrayList;
import java.util.List;

/**
 * @author taomk
 * @version 1.0
 * @since 15-4-20 下午11:03
 *
 * 虚拟机参数：
 * -Xms100m
 * -Xmx100m
 * -XX:+UseSerialGC
 */
public class OOMForJConsole {
	static class OOMObject {
		public byte [] placeholder = new byte [64 * 1024];
	}

	public static void fillHeap(int num) throws InterruptedException {
		List<OOMObject> list = new ArrayList<>();
		for (int i = 0; i < num; i++) {
			Thread.sleep(50);
			list.add(new OOMObject());
		}
		System.gc();
	}

	public static void main(String [] args) throws InterruptedException {
		fillHeap(1000);
	}
}
